package tests;

import org.junit.Test;

import junit.framework.Assert;
import junit.framework.TestCase;
import terms.Variable;

/**
 * 31 mars 2012
 * Ecole des Mines de Nantes
 * Major in Information and Communications Systems Engineering.
 * @author Pierre Reliquet
 */
public class VariableTest extends TestCase {
    /**
     * var a variable used to perform tests.
     */
    private Variable var;
    /**
     * var1 a variable used to perform tests.
     */
    private Variable var1;

    @Override
    protected void setUp() throws Exception {
        this.var = new Variable("");
        this.var1 = new Variable("var");
    }

    /**
     * Test method for {@link terms.Variable#Variable()}.
     */
    @Test
    public void testVariable() {
        Assert.assertEquals(var.getName(), "");
    }

    /**
     * Test method for {@link terms.Variable#equals(java.lang.Object)}.
     */
    @Test
    public void testEqualsObject() {
        Assert.assertTrue(this.var1.equals(this.var1));
        Assert.assertFalse(this.var1.equals(1));
    }

    /**
     * Test method for {@link terms.Variable#getLength()}.
     */
    @Test
    public void testGetLength() {
        Assert.assertTrue(this.var.getLength() == 1);
    }

    /**
     * Test method for {@link terms.Variable#getName()}.
     */
    @Test
    public void testGetName() {
        Assert.assertTrue(this.var1.getName().equals("var"));
    }

    /**
     * Test method for {@link terms.Variable#getRest()}.
     */
    @Test
    public void testGetRest() {
        Assert.assertTrue(null == this.var1.getRest());
    }

    /**
     * Test method for {@link terms.Variable#hashCode()}.
     */
    @Test
    public void testHashCode() {
        Assert.assertTrue(this.var1.hashCode() == this.var1.getName()
                .hashCode());
    }

    /**
     * Test method for {@link terms.Variable#isRest()}.
     */
    @Test
    public void testIsRest() {
        Assert.assertFalse(this.var.isRest());
    }

    /**
     * Test method for {@link terms.Variable#setName(java.lang.String)}.
     */
    @Test
    public void testSetName() {
        this.var.setName("changeNameVar");
        Assert.assertTrue(this.var.getName().equals("changeNameVar"));
    }

    /**
     * Test method for {@link terms.Variable#toString()}.
     */
    @Test
    public void testToString() {
        Assert.assertTrue(this.var1.toString().equals("var"));
    }
}
